Allow -q (initial query) to work with -i (input files)#626
Open
dlevy-msft-sql wants to merge 6 commits intomicrosoft:mainfrom
Open
Allow -q (initial query) to work with -i (input files)#626dlevy-msft-sql wants to merge 6 commits intomicrosoft:mainfrom
dlevy-msft-sql wants to merge 6 commits intomicrosoft:mainfrom
Conversation
Previously -q and -i were mutually exclusive. Now the initial query (-q) runs first, then the input files (-i) are processed. This is useful for setting session options before running scripts. Example: sqlcmd -S server -q 'SET PARSEONLY ON' -i script.sql The -Q flag (query and exit) remains mutually exclusive with -i since -Q causes sqlcmd to exit immediately after the query. Fixes microsoft#389
There was a problem hiding this comment.
Pull request overview
This PR enables the -q (initial query) flag to work alongside -i (input files), allowing users to set session options before running scripts. Previously, -q was mutually exclusive with -i, but now the initial query runs first, followed by the input files. The -Q (query and exit) flag remains mutually exclusive with -i as expected.
Changes:
- Modified validation to allow
-iwith-qwhile keeping-iand-Qmutually exclusive - Updated run logic to execute
-qbefore processing-ifiles - Updated flag descriptions and documentation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/sqlcmd/sqlcmd.go | Modified validation logic to distinguish between -q and -Q, updated run logic to execute initial query before input files, and updated flag description |
| cmd/sqlcmd/sqlcmd_test.go | Updated test expectations to reflect that only -Q (not -q) is mutually exclusive with -i, added test for -q with -i combination |
| README.md | Added documentation for the new feature with example usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix typo: '-i' instead of 'i' in mutuallyExclusiveError call - Add InitialQuery check to prevent double s.Run() when using -q alone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR allows the
-q(initial query) flag to be used with-i(input files), enabling users to set session options before running scripts.Changes
-iwith-Q(not-q)-qfirst, then process-ifiles-iflag description to document the new behaviorUsage
The initial query runs first, then the input files are processed.
Notes
-Qflag (query and exit) remains mutually exclusive with-isince-Qcauses sqlcmd to exit immediately after the queryFixes #389